﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Collections.Specialized;
using System.IO;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;
using System.Diagnostics;

namespace Rabbit.Utils
{
    public class Common
    {
        public static ListBoxItem GetListBoxItemFromChild(DependencyObject d)
        {
            if (VisualTreeHelper.GetParent(d).GetType() == typeof(ListBoxItem))
            {
                return VisualTreeHelper.GetParent(d) as ListBoxItem;
            }
            else
            {
                return GetListBoxItemFromChild(VisualTreeHelper.GetParent(d));
            }
        }
      
        public static void OpenUserPage(long userID)
        {
            OpenWebPage(
                string.Format("{0}{1}",
                Application.Current.Resources["UserBlogPrefix"].ToString(),
                userID));
        }

        public static void OpenWebPage(string url)
        {
            try
            {
                Process.Start(url);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }

    public static class Configuration
    {
        public static readonly int PageSize = 10;
        public static readonly double MaxMessageUpdateIntervalUserCanSet = 600;
        public static readonly double MinMessageUpdateIntervalUserCanSet = 30;
        public static readonly double MinMessageUpdateInterval = 10;
        public static readonly double MaxMessageUpdateInterval = 600;
    }
}
